/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.jm.financeiro.entity;

import br.jm.financeiro.filter.ConfiguraCampoAnnotation;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;
import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;

/**
 *
 * @author joao
 */
@Entity
@Table(name = "cliente", catalog = "salao", schema = "public")
public class Cliente implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "cliente_id_cliente_seq")
    @SequenceGenerator(name = "cliente_id_cliente_seq", sequenceName = "cliente_id_cliente_seq", initialValue = 1, allocationSize = 1)
    @Column(name = "id_cliente")
    @JoinColumn(name = "id_cliente",
    referencedColumnName = "id_cliente",
    nullable = false,
    insertable = true,
    updatable = false)
    private Integer idCliente;
    @Basic(optional = false)
    @Column(name = "tip_cliente", nullable = false, length = 1)
    private String tipCliente;
    @Basic(optional = false)
    @Column(name = "nom_cliente", nullable = false, length = 100)
    private String nomCliente;
    @Basic(optional = true)
    @Column(name = "nom_fantasia", nullable = true, length = 100)
    private String nomFantasia;
    @Basic(optional = false)
    @Column(name = "num_cpf", nullable = false, length = 18)
    private String numCpf;
    @Column(name = "tip_sexo", length = 1)
    private String tipSexo;
    @Column(name = "dsc_email", length = 200)
    private String dscEmail;
    @Column(name = "dsc_site", length = 200)
    private String dscSite;
    @Column(name = "dsc_obs", columnDefinition="text")
    private String dscObs;
    @Column(name = "dsc_historico", columnDefinition="text")
    private String dscHistorico;
    @Transient
    private String dscTipo;
    @JoinColumn(name = "id_categoria", referencedColumnName = "id_categoria", nullable = false)
    @ManyToOne(optional = false)
    @ConfiguraCampoAnnotation(tipo = "String", pesquisa = "idCategoria.dscCategoria", campo = "dsc_categoria", nomeTabela = "cliente", nomeTabelJoin = "categoria")
    private Categoria idCategoria;
    @Basic(optional = false)
    @Column(name = "dat_nasc_abert", nullable = false)
    @Temporal(TemporalType.DATE)
    private Date datNascAbert;
    @Column(name = "sta_cliente", length = 1)
    private String staCliente;
    
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "idCliente")
    @LazyCollection(LazyCollectionOption.FALSE)
    @org.hibernate.annotations.Cascade(org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
    private List<ClienteEndereco> clienteEnderecoList;
    
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "idCliente")
    @LazyCollection(LazyCollectionOption.FALSE)
    @org.hibernate.annotations.Cascade(org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
    private List<ClienteEnderecoTelefone> clienteEnderecoTelefoneList;
    
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "idCliente")
    @LazyCollection(LazyCollectionOption.FALSE)
    @org.hibernate.annotations.Cascade(org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
    private List<Empreendimento> clienteEmpreendimentoList;
    
    @Transient
    private String dscStaCliente;

    public Cliente() {
    }

    public Cliente(Integer idCliente) {
        this.idCliente = idCliente;
    }

    public Cliente(Integer idCliente, String tipCliente, String nomCliente, String numCpf, Date datNascAbert) {
        this.idCliente = idCliente;
        this.tipCliente = tipCliente;
        this.nomCliente = nomCliente;
        this.numCpf = numCpf;
        this.datNascAbert = datNascAbert;
    }

    public Integer getIdCliente() {
        return idCliente;
    }

    public void setIdCliente(Integer idCliente) {
        this.idCliente = idCliente;
    }

    public String getTipCliente() {
        return tipCliente;
    }

    public void setTipCliente(String tipCliente) {
        this.tipCliente = tipCliente;
    }

    public String getNomCliente() {
        return nomCliente;
    }

    public void setNomCliente(String nomCliente) {
        this.nomCliente = nomCliente;
    }

    public String getNumCpf() {
        return numCpf;
    }

    public void setNumCpf(String numCpf) {
        this.numCpf = numCpf;
    }

    public Date getDatNascAbert() {
        return datNascAbert;
    }

    public void setDatNascAbert(Date datNascAbert) {
        this.datNascAbert = datNascAbert;
    }

    public String getTipSexo() {
        return tipSexo;
    }

    public void setTipSexo(String tipSexo) {
        this.tipSexo = tipSexo;
    }

    public String getDscEmail() {
        return dscEmail;
    }

    public void setDscEmail(String dscEmail) {
        this.dscEmail = dscEmail;
    }

    public String getDscSite() {
        return dscSite;
    }

    public void setDscSite(String dscSite) {
        this.dscSite = dscSite;
    }

    public String getDscObs() {
        return dscObs;
    }

    public void setDscObs(String dscObs) {
        this.dscObs = dscObs;
    }

    public String getDscHistorico() {
        return dscHistorico;
    }

    public void setDscHistorico(String dscHistorico) {
        this.dscHistorico = dscHistorico;
    }

    public Categoria getIdCategoria() {
        return idCategoria;
    }

    public void setIdCategoria(Categoria idCategoria) {
        this.idCategoria = idCategoria;
    }

    public String getDscTipo() {
        if (this.tipCliente != null) {
            if (this.tipCliente.equals("F")) {
                this.dscTipo = "Física";
            } else {
                this.dscTipo = "Jurídica";
            }
        }
        return dscTipo;
    }

    public void setDscTipo(String dscTipo) {
        this.dscTipo = dscTipo;
    }

    public List<ClienteEndereco> getClienteEnderecoList() {
        return clienteEnderecoList;
    }

    public void setClienteEnderecoList(List<ClienteEndereco> clienteEnderecoList) {
        this.clienteEnderecoList = clienteEnderecoList;
    }

    public List<ClienteEnderecoTelefone> getClienteEnderecoTelefoneList() {
        return clienteEnderecoTelefoneList;
    }

    public void setClienteEnderecoTelefoneList(List<ClienteEnderecoTelefone> clienteEnderecoTelefoneList) {
        this.clienteEnderecoTelefoneList = clienteEnderecoTelefoneList;
    }

    public String getNomFantasia() {
        return nomFantasia;
    }

    public void setNomFantasia(String nomFantasia) {
        this.nomFantasia = nomFantasia;
    }

    public List<Empreendimento> getClienteEmpreendimentoList() {
        return clienteEmpreendimentoList;
    }

    public void setClienteEmpreendimentoList(List<Empreendimento> clienteEmpreendimentoList) {
        this.clienteEmpreendimentoList = clienteEmpreendimentoList;
    }

    public String getStaCliente() {
        return staCliente;
    }

    public void setStaCliente(String staCliente) {
        this.staCliente = staCliente;
    }

    public String getDscStaCliente() {
        if (this.staCliente != null) {
            if (this.staCliente.equals("A")) {
                this.dscStaCliente = "Ativo";
            } else if (this.staCliente.equals("P")) {
                this.dscStaCliente = "Prospects";
            } else {
                this.dscStaCliente = "Inativo"; 
            }
        } else {
            this.dscStaCliente = "Inativo";
        }
        return dscStaCliente;
    }

    public void setDscStaCliente(String dscStaCliente) {
        this.dscStaCliente = dscStaCliente;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idCliente != null ? idCliente.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Cliente)) {
            return false;
        }
        Cliente other = (Cliente) object;
        if ((this.idCliente == null && other.idCliente != null) || (this.idCliente != null && !this.idCliente.equals(other.idCliente))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "br.jm.financeiro.entity.Cliente[ idCliente=" + idCliente + " ]";
    }
}
